﻿<div class="ph-tabs">
    <ul>
        <li class="k-state-active">成绩明细列表</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <div style="display: inline-block; ">
                <select id="selArchive" style="width: 300px"></select>
            </div>
            <div style="display: inline-block; ">
                <select id="selSubject"></select>
            </div>
            <div style="display: inline-block;">
                <select id="selClass"></select>
            </div>
        </div>
        <div class="k-block divToolbar">
            <span class="k-textbox k-space-right">
                <input type="text" placeholder="学生姓名或身份证" id="txtKey" />
                <a href="javascript:Filter()" class="k-icon k-i-search">&nbsp;</a>
            </span>
            <a class="k-button" onclick="Export()"><span class="k-icon k-i-calendar"></span><span>导出所有成绩</span></a>
        </div>
        <div id="grid_marks" style="text-align: center"></div>

        <form id="exportForm" method="post" action="/Achievements/Mark/Export" target="_blank" style="display: none">
            <input type="hidden" name="archiveGuid" id="df_ArchiveGuid" />
            <input type="hidden" name="key" id="df_Key" />
        </form>
    </div>
</div>

<script class="init">
    LocatedMenu("体测数据", "成绩修改");

    $("#selSubject").kendoDropDownList({
        optionLabel: {
            ID: 0,
            SubjectName: "所有项目"
        },
        dataTextField: "SubjectName",
        dataValueField: "ID",
        dataSource: Whale.dataSource({
            url: "/Standard/Subject/GetSubjects"
        }),
        change: function (e) { Filter(); }
    });

    $("#selArchive").kendoDropDownList({
        dataTextField: "Title",
        dataValueField: "Guid",
        dataSource: Whale.dataSource({
            url: "/Achievements/Archive/Gets",
            getParameters: function () {
                return {
                    aType: 2,
                    expired: false
                }
            }
        }),
        dataBound: function (e) {
            if (this.dataSource.data().length == 0) {
                this.setDataSource(new kendo.data.DataSource({
                    data: [{ Title: "暂无档案", Guid: "" }]
                }));
            }
        },
        change: function (e) { Filter(); }
    });

    $("#selClass").kendoDropDownList({
        optionLabel: {
            ID: 0,
            ClassName: "所有班级"
        },
        dataTextField: "ClassName",
        dataValueField: "ID",
        dataSource: Whale.dataSource({
            url: "/School/Class/GetClasses",
            getParameters: function () {
                return { schoolGuid: "@PH.Web.Global.WebContext.CurrentSchool.Guid" }
            }
        }),
        change: function (e) { Filter(); }
    });

    function Filter() {
        $("#grid_marks").data("kendoGrid").dataSource.page(0);
    }

    function Export() {
        $("#df_ArchiveGuid").val($("#selArchive").data("kendoDropDownList").value());
        //$("#df_Key").val($("#txtKey").val());
        $("#exportForm").submit();
    }
</script>

<script class="grid_marks_config">
    $(function () {
        var fields = [{
            title: "身份证",
            field: "StudentNo",
            sortable: false,
            width: 150
        }, {
            title: "班级",
            field: "ClassName",
            sortable: false,
            width: 130
        }, {
            title: "姓名",
            field: "StudentName",
            sortable: false,
            width: 100
        }, {
            title: "性别",
            field: "Sex",
            template: "#=GetSexString(Sex)#",
            sortable: false,
            width: 60
        }, {
            title: "项目",
            field: "Subject.SubjectName",
            sortable: false,
            width: 200
        }, {
            title: "成绩",
            field: "Achievement",
            template: "#=ShowAchievement(Achievement,Subject.Category)#",
            sortable: false,
            width: 100
        }, {
            title: "得分",
            field: "Score",
            sortable: true,
            width: 70
        }, {
            title: "评价",
            field: "Description",
            sortable: false,
            width: 100
        }, {
            title: "加分",
            field: "AdditionalScore",
            sortable: false,
            width: 60
        }, {
            title: "操作",
            template: "#=GetOperations(ID)#",
            attributes: { style: "text-align:left" },
            width: 100
        }, {}];

        $("#grid_marks").kendoGrid({
            columns: fields,
            dataSource: Whale.dataSource({
                url: "/Achivevments/Mark/Gets",
                getParameters: function () {
                    var cid = $("#selClass").data("kendoDropDownList").value();
                    var sid = $("#selSubject").data("kendoDropDownList").value();
                    return {
                        aGuid: $("#selArchive").data("kendoDropDownList").value(),
                        sGuid: "@PH.Web.Global.WebContext.CurrentSchool.Guid",
                        getSubject: true,
                        getClassName: true,
                        getStudentName:true,
                        autoPass: false,
                        key: $("#txtKey").val(),
                        classID: cid == "" ? 0 : cid,
                        subjectID: sid == "" ? 0 : sid
                    };
                },
                pageSize: 20,
                serverSorting: true,
                sort: {
                    field: "Score",
                    dir: "desc"
                }
            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            },
            sortable: true
        });
    });

    function ShowAchievement(achievement, category) {
        if (category == 3) {
            return ShowTime(achievement);
        }
        else
            return achievement;
    }

    function GetOperations(id) {
        var html = "<button class='k-button' onclick=\"Edit(" + id + ")\"><span class='k-icon k-i-pencil'></span><span>修改</span></button>";
        return html;
    }

    function Edit(id) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "修改学生成绩" });
            wndGeneralEdit.refresh({ url: "/Achievements/Mark/Edit/" + id });
            wndGeneralEdit.open();
        }
    }
</script>
